package com.jimmy.medical.controller;

import com.jimmy.medical.entity.Message;
import com.jimmy.medical.entity.PhoneCall;
import com.jimmy.medical.model.FeeInfo;
import com.jimmy.medical.service.ISignFlowOrderService;
import com.jimmy.medical.util.AjaxUtils;
import com.jimmy.medical.util.Func_T;
import com.jimmy.medical.model.AjaxResult;
import com.jimmy.medical.model.SignInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/signFlow")
public class SignFlowOrderController {

    @Autowired
    private ISignFlowOrderService signFlowOrderService;

    /**
     * 确认接单
     *
     * @param userId
     * @param： flowOrderId
     * @return
     */
    @RequestMapping("/affirm")
    @ResponseBody
    public AjaxResult<Long> affirm(final Long flowOrderId, final Long userId) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return signFlowOrderService.saveAffirmInfo(flowOrderId, userId);
            }
        });
    }

    /**
     * 致电客户
     *
     * @return
     * @param: call
     */
    @RequestMapping("/dialToCustomer")
    @ResponseBody
    public AjaxResult<Long> dialToCustomer(final Long orderId, final Long userId) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return signFlowOrderService.saveAffirmDial(orderId, userId);
            }
        });
    }

    /**
     * 挂号登记界面
     *
     * @param flowOrderId
     * @return
     */
    @RequestMapping("/goSign")
    @ResponseBody
    public AjaxResult<SignInfo> goSign(final Long flowOrderId) {
        return AjaxUtils.process(new Func_T<SignInfo>() {
            @Override
            public SignInfo invoke() throws Exception {
                return signFlowOrderService.getSignInfo(flowOrderId);
            }
        });
    }

    /**
     * 挂号登记
     *
     * @param info
     * @return
     */
    @RequestMapping("/sign")
    @ResponseBody
    public AjaxResult<Long> sign(final SignInfo info) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return signFlowOrderService.saveSignInfo(info, 3);
            }
        });
    }

    /**
     * 电话通知
     *
     * @param call
     * @return
     */
    @RequestMapping("/noticeToCustomer")
    @ResponseBody
    public AjaxResult<Long> noticeToCustomer(final PhoneCall call) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return signFlowOrderService.saveNoticeInfo(call);
            }
        });
    }

    /**
     * 短信通知
     *
     * @param message
     * @return
     */
    @RequestMapping("/messageToCustomer")
    @ResponseBody
    public AjaxResult<Long> messageToCustomer(final Message message) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return signFlowOrderService.saveMessageFlow(message);
            }
        });
    }

    /**
     * 完成挂号登记
     * @return
     */
    @RequestMapping("/submitSign")
    @ResponseBody
    public AjaxResult<String> submitSign(final Long flowOrderId, final  Long userId) {
        return AjaxUtils.process(new Func_T<String>() {
            @Override
            public String invoke() throws Exception {
                signFlowOrderService.submitSign(flowOrderId, userId);
                return "200";
            }
        });
    }
}
